﻿namespace Leetcode.N0065;

public class Solution
{
    public bool IsNumber(string s)
    {
        var flgs = new bool[256];
        flgs['0'] = true;
        flgs['1'] = true;
        flgs['2'] = true;
        flgs['3'] = true;
        flgs['4'] = true;
        flgs['5'] = true;
        flgs['6'] = true;
        flgs['7'] = true;
        flgs['8'] = true;
        flgs['9'] = true;
        flgs['e'] = false;
        flgs['E'] = false;
        flgs['.'] = true;
        flgs['+'] = true;
        flgs['-'] = true;
        bool hasNumer = false;
        bool eFlg = true;

        for (int i = 0; i < s.Length; i++)
        {
            if (flgs[s[i]] == false)
            {
                return false;
            }

            if (s[i] == '+' || s[i] == '-')
            {
                flgs['+'] = false;
                flgs['-'] = false;
                continue;
            }

            if (s[i] == '.')
            {
                flgs['+'] = false;
                flgs['-'] = false;
                flgs['.'] = false;
                continue;
            }

            if (s[i] == 'e' || s[i] == 'E')
            {
                flgs['e'] = false;
                flgs['E'] = false;
                flgs['-'] = true;
                flgs['+'] = true;
                flgs['.'] = false;
                hasNumer = false;
                continue;
            }

            if (flgs['e'] == false && eFlg)
            {
                eFlg = false;
                flgs['e'] = true;
                flgs['E'] = true;
            }
            flgs['+'] = false;
            flgs['-'] = false;
            hasNumer = true;
        }

        return hasNumer;
    }
}
